package gdr.dev.creator;

import gdr.battle.core.BattleContainer;
import gdr.battle.data.map.Position;
import gdr.dev.Util;
import gdr.player.DefaultPlayer;

import java.util.ArrayList;

public class Area{
	protected int x;
	protected int y;
	protected int width;
	protected int height;
	
	public Area(){
	}
	public Area(int x, int y, int width, int height){
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}
	
	public Position getFreePos(BattleContainer container, DefaultPlayer player){
		ArrayList<Position> posizioni = new ArrayList<Position>();
		for (int i=x; i<x+width; i++)
			for (int j=y; j<y+height; j++)
				if (container.getData().getMap().isStazionabile(new Position(i, j, 1), player))
					posizioni.add(new Position(i, j, container.getData().getMap().getBattleMapUnit(new Position(i, j, 1)).getPos().getZ())); 
		if (posizioni.isEmpty()) return null;
		return posizioni.get(Util.random(posizioni.size()));
	}
	
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public int getHeight() {
		return height;
	}
	public void setHeight(int height) {
		this.height = height;
	}
}
